package com.bit.strongbaby;

import java.security.spec.MGF1ParameterSpec;

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class JoinActivity extends Activity {
	EditText ed_k;
	EditText ed_p;
	EditText ed_m;
	Button btn1;
	Button btn2;
	
	WordDBHelper mHelper;
	WordDBHelper2 mHelper2;
	SQLiteDatabase db;
	SQLiteDatabase db2;
	ContentValues row;
	
	String ed1;
	String ed2;
	String ed3;
	
	String k;
	String p;
	String m;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_join);

		ed_k = (EditText)findViewById(R.id.editText1);
		ed_p = (EditText)findViewById(R.id.editText2);
		ed_m = (EditText)findViewById(R.id.editText3);
		
		mHelper = new WordDBHelper(this);
		mHelper2 = new WordDBHelper2(this);

		btn1 = (Button)findViewById(R.id.btn111);
		btn1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				ed1 = ed_k.getText().toString();
				ed2 = ed_p.getText().toString();
				ed3 = ed_m.getText().toString();
				
				db = mHelper.getWritableDatabase();
				db2 = mHelper2.getWritableDatabase();
//				row = new ContentValues();
//				row.put("name", ed1);
//				row.put("pound", ed2);
//				row.put("month", ed3);
//				db.insert("baby_info", null, row);
				db.execSQL("insert into baby_info values ( null, '"+ed1+"', "+ed2+", "+ed3+");");


				db2.execSQL("INSERT INTO baby_grow VALUES (1, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (2, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (3, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (4, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (5, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (6, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (7, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (8, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (9, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (10, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (11, null, '');");
				db2.execSQL("INSERT INTO baby_grow VALUES (12, null, '');");
				
				db.close();
				db2.close();
				
				Intent ini = new Intent(getBaseContext(), MenuActivity.class);
				startActivity(ini);
				finish();
			}
		});
		btn2 = (Button)findViewById(R.id.btn222);
		btn2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				db = mHelper.getWritableDatabase();
				db2 = mHelper2.getWritableDatabase();
				
				db.execSQL("DELETE FROM baby_info");
				db2.execSQL("DELETE FROM baby_grow");
				Toast toast = Toast.makeText(getApplicationContext(), 
						"아이의 정보가 삭제되었습니다. App을 다시 실행시켜주세요", 0);
				toast.show();	
				mHelper.close();
				mHelper2.close();
				finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the` action bar if it is present.
		getMenuInflater().inflate(R.menu.join, menu);
		return true;
	}

}

